<template>
	<view class="uni-product-list" v-if="productList.length>0">
		<view class="uni-product" v-for="(product,index) in productList" :key="index" @click="pathUrl(product.id)">
			<view class="image-view">
				<image v-if="product.image" class="uni-product-image" :src="product.image.split(',')[0]"></image>
			</view>
			<view class="uni-product-title">{{product.name}}</view>
			<view class="uni-product-price">
				<!-- <text class="uni-product-price-favour">￥{{product.originalPrice}}</text> -->
				<text class="uni-product-price-original">￥{{product.price}}</text>
				<!-- <text class="uni-product-tip">{{product.tip}}</text> -->
			</view>
		</view>
		
	</view>
	<!-- <view v-else style="display: flex;justify-content: center;align-items: center;height: 100vh;">
		<image src="@/static/goods/empty.png" mode=""></image>
	</view> -->
	<empty v-else></empty>
</template>

<script>
	export default {
		data() {
			return {
				title: 'product-list',
				productList: [],
				renderImage: false,
				id: '',
				searchVal: {
					pageIndex: 1,
					pageSize: 10,
					key: "",
					brandId: "00000000-0000-0000-0000-000000000000",
					catgoryId: "00000000-0000-0000-0000-000000000000",
					sorting: ""
				}
			};
		},
		methods: {
			getData() {
				this.searchVal.catgoryId = this.id
				this.$ajax.getall(this.searchVal).then(res => {
					this.productList = res.data
				})
			},
			// 跳转详情
			pathUrl(id) {
				uni.navigateTo({
					url: `/pages/good/product/product?id=${id}`
				})
			},
		},
		
		onLoad(e) {
			this.searchVal.key=e.key||''
			this.id = e.id ? e.id : '00000000-0000-0000-0000-000000000000'
			this.getData()
			// this.loadData();
			// setTimeout(() => {
			//     this.renderImage = true;
			// }, 300);
		},
		onPullDownRefresh() {
			this.loadData('refresh');
			// 实际开发中通常是网络请求，加载完数据后就停止。这里仅做演示，加延迟为了体现出效果。
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 2000);
		},
		onReachBottom() {
			this.loadData();
		}
	};
</script>

<style>
	/* product */
	page {
		background: #F8F8F8;
	}

	view {
		font-size: 28upx;
	}

	.uni-product-list {
		display: flex;
		width: 100%;
		flex-wrap: wrap;
		flex-direction: row;
	}

	.uni-product {
		padding: 20upx;
		display: flex;
		flex-direction: column;
	}

	.image-view {
		height: 330upx;
		width: 330upx;
		margin: 12upx 0;
	}

	.uni-product-image {
		height: 330upx;
		width: 330upx;
	}

	.uni-product-title {
		width: 300upx;
		word-break: break-all;
		display: -webkit-box;
		overflow: hidden;
		line-height: 1.5;
		text-overflow: ellipsis;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
	}

	.uni-product-price {
		margin-top: 10upx;
		font-size: 28upx;
		line-height: 1.5;
		position: relative;
	}

	.uni-product-price-original {
		color: #e80080;
	}

	.uni-product-price-favour {
		color: #888888;
		text-decoration: line-through;
		margin-left: 10upx;
	}

	.uni-product-tip {
		position: absolute;
		right: 10upx;
		background-color: #ff3333;
		color: #ffffff;
		padding: 0 10upx;
		border-radius: 5upx;
	}
</style>